function loadFiles(options){
  let src = (options.src || options.href).split('/');
  if(document.getElementById(options.id) || isInclude(src[src.length - 1])){
    if(options.onload){
      options.onload();
    }
    return;
  }
  let dom;
  if(options.type == 'script'){
    dom = document.createElement('script');
  }else{
    dom = document.createElement('link');
  }
  dom.src = options.src || '';
  dom.href = options.href || '';
  dom.id = options.id || '';
  dom.onload = options.onload;
  dom.rel = options.rel || '';
  document.head.appendChild(dom);
}

function wfGetCookie(name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if (arr = document.cookie.match(reg))
      return unescape(arr[2]);
  else
      return null;
}

function escapeHTML(str) {
  return str.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

/*获取服务器域名*/
function getServer(server) {
  var host = document.domain;
  var hostArr = host.split(".");
  var domain = "//" + server + ".mbalib.com";
  if (hostArr[1] == 'dev' || hostArr[1] == 'test' || hostArr[1] == 'test2') {
      domain = "//" + server + "." + hostArr[1] + ".mbalib.com";
      if (server == 'img' && (hostArr[1] == 'test2' || hostArr[1] == 'test')) {
          domain = "//static." + hostArr[1] + ".mbalib.com";
      }
  }
  return location.protocol + domain;
}

/**
 *
 * @param fmt eg.yyyy-MM-dd
 * @param val eg.new Date()
 * @returns {*} eg.2019-12-20
 */
 function format(fmt, val) {
  let o = {
      "M+": val.getMonth() + 1, //月份
      "d+": val.getDate(), //日
      "h+": val.getHours(), //小时
      "m+": val.getMinutes(), //分
      "s+": val.getSeconds(), //秒
      "q+": Math.floor((val.getMonth() + 3) / 3), //季度
      "S": val.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (val.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (let k in o)
      if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
};

/**
 * 时间戳格式化函数
 * @param  {string} format    格式
 * @param  {int}    timestamp 要格式化的时间 默认为当前时间
 * @return {string}           格式化的时间字符串
 */
 function wfDate(format, timestamp) {
  var a, jsdate = ((timestamp) ? new Date(timestamp * 1000) : new Date());
  var pad = function(n, c) {
      if ((n = n + "").length < c) {
          return new Array(++c - n.length).join("0") + n;
      } else {
          return n;
      }
  };
  var txt_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  // var txt_weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
  var txt_ordin = { 1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st" };
  var txt_months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  // var txt_months = [" ", "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
  var f = {
      // Day
      d: function() { return pad(f.j(), 2) },
      D: function() { return f.l().substr(0, 3) },
      j: function() { return jsdate.getDate() },
      l: function() { return txt_weekdays[f.w()] },
      N: function() { return f.w() + 1 },
      S: function() { return txt_ordin[f.j()] ? txt_ordin[f.j()] : 'th' },
      w: function() { return jsdate.getDay() },
      z: function() { return (jsdate - new Date(jsdate.getFullYear() + "/1/1")) / 864e5 >> 0 },

      // Week
      W: function() {
          var a = f.z(),
              b = 364 + f.L() - a;
          var nd2, nd = (new Date(jsdate.getFullYear() + "/1/1").getDay() || 7) - 1;
          if (b <= 2 && ((jsdate.getDay() || 7) - 1) <= 2 - b) {
              return 1;
          } else {
              if (a <= 2 && nd >= 4 && a >= (6 - nd)) {
                  nd2 = new Date(jsdate.getFullYear() - 1 + "/12/31");
                  return date("W", Math.round(nd2.getTime() / 1000));
              } else {
                  return (1 + (nd <= 3 ? ((a + nd) / 7) : (a - (7 - nd)) / 7) >> 0);
              }
          }
      },

      // Month
      F: function() { return txt_months[f.n()] },
      m: function() { return pad(f.n(), 2) },
      M: function() { return f.F().substr(0, 3) },
      n: function() { return jsdate.getMonth() + 1 },
      t: function() {
          var n;
          if ((n = jsdate.getMonth() + 1) == 2) {
              return 28 + f.L();
          } else {
              if (n & 1 && n < 8 || !(n & 1) && n > 7) {
                  return 31;
              } else {
                  return 30;
              }
          }
      },

      // Year
      L: function() { var y = f.Y(); return (!(y & 3) && (y % 1e2 || !(y % 4e2))) ? 1 : 0 },
      //o not supported yet
      Y: function() { return jsdate.getFullYear() },
      y: function() { return (jsdate.getFullYear() + "").slice(2) },

      // Time
      a: function() { return jsdate.getHours() > 11 ? "pm" : "am" },
      A: function() { return f.a().toUpperCase() },
      B: function() {
          // peter paul koch:
          var off = (jsdate.getTimezoneOffset() + 60) * 60;
          var theSeconds = (jsdate.getHours() * 3600) + (jsdate.getMinutes() * 60) + jsdate.getSeconds() + off;
          var beat = Math.floor(theSeconds / 86.4);
          if (beat > 1000) beat -= 1000;
          if (beat < 0) beat += 1000;
          if ((String(beat)).length == 1) beat = "00" + beat;
          if ((String(beat)).length == 2) beat = "0" + beat;
          return beat;
      },
      g: function() { return jsdate.getHours() % 12 || 12 },
      G: function() { return jsdate.getHours() },
      h: function() { return pad(f.g(), 2) },
      H: function() { return pad(jsdate.getHours(), 2) },
      i: function() { return pad(jsdate.getMinutes(), 2) },
      s: function() { return pad(jsdate.getSeconds(), 2) },
      //u not supported yet

      // Timezone
      //e not supported yet
      //I not supported yet
      O: function() {
          var t = pad(Math.abs(jsdate.getTimezoneOffset() / 60 * 100), 4);
          if (jsdate.getTimezoneOffset() > 0) t = "-" + t;
          else t = "+" + t;
          return t;
      },
      P: function() { var O = f.O(); return (O.substr(0, 3) + ":" + O.substr(3, 2)) },
      //T not supported yet
      //Z not supported yet

      // Full Date/Time
      c: function() { return f.Y() + "-" + f.m() + "-" + f.d() + "T" + f.h() + ":" + f.i() + ":" + f.s() + f.P() },
      //r not supported yet
      U: function() { return Math.round(jsdate.getTime() / 1000) }
  };

  return format.replace(/[\\]?([a-zA-Z])/g, function(t, s) {
      if (t != s) {
          // escaped
          ret = s;
      } else if (f[s]) {
          // a date function exists
          ret = f[s]();
      } else {
          // nothing special
          ret = s;
      }
      return ret;
  });
}

function isInclude(name){
  var js= /js$/i.test(name);
  var es=document.getElementsByTagName(js?'script':'link');
  for(var i=0;i<es.length;i++)
    if(es[i][js?'src':'href'].indexOf(name)!=-1)return true;
  return false;
}

function formateDate(val) {
  let day1 = new Date();
  day1.setDate(day1.getDate() - 1);
  let yesterday = format("yyyy-MM-dd", day1);
  let today = wfDate("Y-m-d");
  let date = val.substr(0, 10);
  let hours = val.substr(11, 5);
  if (date == today) {
    return hours;
  } else if (date == yesterday) {
    return "昨天 " + hours;
  } else {
    return date + " " + hours;
  }
}

var choose = null;
var token = wfGetCookie("wikidbAccessToken");
var smallPopObj = {
  groupList: [],
  groupLogoUrl: '',
  messageList: [],
  item: null,
  page: 1,
  pageSize: 10,
  im: false,
  float: true,
  noticeCount: 0,
  noticeCountAnother: 0,
}
if (!window.jQuery) {
  loadFiles({
    type: 'script',
    id: 'jqueryjs',
    src: getServer('img')+'/common/jquery/jquery.js',
  }); // 没有jquery时引入jquery
}

loadFiles({
  type: 'link',
  id: 'tmccss',
  rel: 'stylesheet',
  href: getServer('img')+'/common/tmc/tmc.css',
});
loadFiles({
  type: 'script',
  id: 'iconfontjs',
  src: getServer('img')+'/doc/icon/iconfont_copy.js',
});

function noticePop() {
  if (!$(".notification").length) return;

  // 启动渲染
  let str =
    '<div class="noticePop" style="display:none;">' +
      '<div class="notice-top"><div class="information-choose">通知</div><div>私信</div></div>' +
      '<div class="loading" style="display:none"><i>正在加载</i></div><ul id="newList"></ul>' +
      '<div id="view-all">查看全部</div>' +
    "</div>";
  $(".notification").append(str);

  hasNewMessage();

  var host=document.domain;
  var f = host.split('.');
  // console.log(f);
  var from = f[0];

  if(from == 'doc' || from == 'ke' || from == 'www' || from == 'passport' || from == 'wiki'|| from == 'news'){
    $(".notification").mouseenter(function (e) {
      $(".noticePop").show();
      getGroupListNew(choose || "notice");
      hasNewMessage(choose == "private" ? "notice" : "private");
    });

    $(".notification").mouseleave(function(){
      $(".noticePop").hide();
      hasNewMessage();
    })

    $(".img-not").click(function(){
      window.open('//passport.mbalib.com/user/message');
    })
    $(".openPassport").click(function(){
      window.open('//passport.mbalib.com/user/message');
    })
  } else {
    $(".notification").click(function (e) {
      e.stopPropagation();
      if ($(".noticePop").css("display") == "block") {
        $(".noticePop").hide();
        hasNewMessage();
        return;
      }
      $(".noticePop").show();
      getGroupListNew(choose || "notice");
      hasNewMessage(choose == "private" ? "notice" : "private");
    });
    $("html").click(function () {
      if($(".noticePop").css('display') == 'block'){
        hasNewMessage();
      }
      $(".noticePop").hide();
    });
  }


  $(".noticePop").click(function (e) {
    e.stopPropagation();
  });
  $(".notice-top div").click(function () {
    if ($(this).attr("class")) return;

    $(".notice-top div").removeClass("information-choose");
    $(this).addClass("information-choose");
    choose = choose ? null : "private";
    getGroupListNew(choose || "notice");
    hasNewMessage(choose == "private" ? "notice" : "private");
  });
  $("#view-all").click(function () {
    let str =
      getServer("passport") + "/user/message?type=" + (choose || "notice");
    window.open(str, "_self");
  });
  $("#newList").on("click", "li", function () {
    // 点击跳转到passport页面
    // let str =
    //   getServer("passport") +
    //   "/user/message?type=" +
    //   (choose || "notice") +
    //   "&item=" +
    //   $(this).attr("data-id");
    // window.open(str, "_self");
    smallGroupPop($(this).attr('data-id'));
    // smallLis($(this).attr('data-id'));
  });
}

function smallGroupPop(index){
  $(".noticePop").hide();

  // let item = smallPopObj.groupList.find(function(item){
  //   return item.group_id == index;
  // });

  let item = null
  smallPopObj.groupList.forEach(function(items){
    if(items.group_id == index){
      item = items
    }
  });

  if(!item) return;
  smallPopObj.item = item;

  let calcPx = window.innerWidth - $('html').innerWidth();
  $("html").css({width: "calc(100% - " + calcPx + "px)",height: "100%", overflow: "hidden" });

  if(!$('#infoPop-ups').length){
    let str = '<div id="infoPop-ups">';
    str +=      '<div>';
    str +=      '<div class="flexPop"><div class="titlePop"><h1>' + item.group_name + '</h1><svg class="vector" aria-hidden="true"><use xlink:href="#ic_close"></use></svg></div>';
    str +=      '<div class="hr"></div>';
    str +=      '<div class="infoLoading"><i>正在加载</i></div>';
    str +=      '<div class="messageList"></div>';
    if(item.group_origin_type == 'class'){
      str +=     '<div class="small-bottom"><button id="smallInfo-btn">进入班级</button></div></div>';
    }
    str +=     '</div></div>';
    $("body").append(str);

    // 点击弹窗隐藏
    $('#infoPop-ups .vector').click(function(){
        
      smallPopObj.float = false;
      $('#infoPop-ups').fadeOut();
      $('#maskLayer').fadeOut();
      $('#infoPop-ups .messageList').off('scroll'); // 删除滚动事件
      $('#infoPop-ups .messageList').off("mousewheel DOMMouseScroll"); // 删除鼠标滚动事件
      smallPopObj.page = 1;
      $("html").css({width: "100%", height: "auto", overflow: "visible" });
      hasNewMessage();

    })

    // 进入班级
    $('#smallInfo-btn').click(function(){
      window.open(getServer('ke') + '/#/class/' + smallPopObj.item.group_origin_id)
    })

    $('#infoPop-ups .messageList').on('click','.mainNews',function(){
      if($(this).attr('data-type') == 'class_bulletin'){
        window.open(getServer('ke') + '/#/class/bulletin?message=true&id=' + $(this).attr('data-id') + '&group_id=' + smallPopObj.item.group_origin_id);
      }else if($(this).attr('data-type') == 'star'){
        window.open(getServer('ke') + '/#/star?class_id=' + $(this).attr('data-id'));
      }else if($(this).attr('data-type') == 'class_topic_add'){
        let query = {
          tc_id:item.message_info.tc_id,
          message_id:item.message_id,
        }
        window.open(getServer('ke') + '/#/classTopic/message?tc_id' + $(this).attr('tc-id') + '&message_id=' + $(this).attr('data-id'));
      // }else if(item.message_type=='class_apply'){
        //加入班级

      }else{
        if($(this).attr('data-url')){
          if($(this).attr('data-url').search(/http/) == -1) return
          window.open($(this).attr('data-url'))
          //location.href = $(this).attr('data-url');
        }
      }
    })
  } else {
    $('#infoPop-ups .titlePop h1').html(item.group_name);
    $('#infoPop-ups .messageList').children().remove();
    $('.infoLoading').show();
    if(item.group_origin_type == 'class'){
      $('#infoPop-ups .small-bottom').show();
    }else{
      $('#infoPop-ups .small-bottom').hide();
    }
  }

  $('#infoPop-ups').fadeIn(function(){
    infoMessageList();
  });
}

// 消息详情弹窗接口
function infoMessageList() {
  var qsData = {
    access_token: token,
    group_id: smallPopObj.item.group_id,
    start: smallPopObj.pageSize * (smallPopObj.page - 1),
    num: smallPopObj.pageSize,
    group_origin_id: smallPopObj.item.group_origin_id,
    group_origin_type: smallPopObj.item.group_origin_type,
    group_name: smallPopObj.item.group_name,
  }

  $.ajax({
    url: getServer("www") + "/messageapi/getMessageList",
    data: qsData,
    type: "POST",
    dataType: "json",
    crossDomain: true,
    xhrFields: {
      withCredentials: true,
    },
    success: function (res) {
      if (res.errorno == "10001") {
        freshUserToken(infoMessageList);
        return;
      }
      
      $('.infoLoading').hide();
      $('.lodingList').remove();
      let result = res.data;
      
      if(result && result.length > 0){
        smallPopObj.im = false;
        
        result.forEach(function (item){

          let str = '<div class="time">' + formateDate(item.message_createtime) + '</div>';
              str += '<div class="news ' + (item.message_style == "6" ? 'discuss-main' : '' ) + '">';
              str += '<img src="' + smallPopObj.item.group_logo + '">';
              str += '<div class="mainNews ' + ((item.message_url.search(/http/) == -1) ? '' : 'lineClamp') + '" data-id="' + item.message_id + '" tc_id="' + item.message_info.tc_id + '" data-type="' + item.message_type + '" data-url="' + item.message_url + '">';
          switch (item.message_style){
            case '1':  // 1-标题+内容
              str +=   '<div class="body"><h6>' + item.message_title + '</h6><p>' + item.message_content + '</p></div>';
              str += '</div>';
              break;
            case '2':  // 2-标题+内容+其他信息(暂时没有这个状态，先预存着没写完)
              str +=   '<div class="body"><h6>' + item.message_title + '</h6><p>' + item.message_content + '</p></div>';
              str += '</div>';
              break;
            case '3':  // 3-仅内容
              str +=   '<div class="body"><p style="color: #303133;">' + item.message_content + '</p></div>';
              str += '</div>';
              break;
            case '4':  // 4-标题＋内容＋封面
              str +=   '<div class="body"><h6>' + item.message_title + '</h6><p>' + item.message_content + '</p><img class="im" src="' + item.message_img + '"></div>';
              str += '</div>';
              break;
            case '5':  // 5-封面＋标题＋内容
              str +=  '<img class="im" src="' + item.message_img + '">';
              str +=   '<div class="body"><h6>' + item.message_title + '</h6><p>' + item.message_content + '</p></div>';
              str += '</div>';
              break;
            case '6':  // 6-评论
              str +=  '<div class="body">';
              str +=   '<div class="user-box"><div class="user-avatar"><img src="' + item.message_eventAvatar + '" /></div><div class="user-info"><div class="user-name">' + (item.message_eventNickname ? item.message_eventNickname : '&nbsp;') + '</div><div class="user-time">' + item.message_createtime.split(' ')[0] + '&nbsp;&nbsp;' + item.message_eventText +  '</div></div></div>';
              if(item.message_title){
                str +=   '<div class="discuss-title">' + item.message_title + '</div>';
              }
              str +=   '<div class="discuss-box"><div>' + item.message_content + '</div></div>';
              str += '</div></div>';
              break;
          }
          str += '</div>';

          $('#infoPop-ups .messageList').prepend(str);
        })

        if(smallPopObj.page == 1){ // 是否为第一页
          if(!$('.im').length) {
            if(smallPopObj.im) return;
            smallPopObj.im = true;
            $('#infoPop-ups .messageList').scrollTop($('#infoPop-ups .messageList')[0].scrollHeight);
          } else {
            $('.im').load(function(){  // 监听图片加载完毕后，获取父元素的高
              if(smallPopObj.im) return;
              smallPopObj.im = true;
              $('#infoPop-ups .messageList').scrollTop($('#infoPop-ups .messageList')[0].scrollHeight);
            })
          }
        }else{
          if(!$('.im').length) {
            if(smallPopObj.im) return;
            smallPopObj.im = true;
            $('#infoPop-ups .messageList').scrollTop($('#infoPop-ups .messageList > div').eq(result.length - 1).offset().top);
          } else {
            $('.im').load(function(){
              if(smallPopObj.im) return;
              smallPopObj.im = true;
              $('#infoPop-ups .messageList').scrollTop($('#infoPop-ups .messageList > div').eq(result.length - 1).offset().top);
            })
          }
        }

        if(smallPopObj.pageSize == result.length){ // 判断是否还有更多消息

          $('#infoPop-ups .messageList').scroll(function(){  // 监听窗口滚动事件

            if($('#infoPop-ups .messageList').scrollTop() == 0){
              let str = '<div class="lodingList"><i class="load">正在加载</i></div>'
              $('#infoPop-ups .messageList').prepend(str);
              smallPopObj.page++;
              infoMessageList();
              $('#infoPop-ups .messageList').off("scroll");
            }
          })
        }
      }
    },
  });
}

// 是否有新消息接口
function hasNewMessage(type) {
  var qsData = {
    access_token: token,
    group_type: type,
  };
  $.ajax({
    url: getServer("www") + "/messageapi/hasNewMessage",
    data: qsData,
    type: "POST",
    dataType: "json",
    crossDomain: true,
    xhrFields: {
      withCredentials: true,
    },
    success: function (res) {
      if (res.errorno == "10001") {
        freshUserToken(hasNewMessage);
        return;
      }
      if(!type){
        if (res.has_new_message >= 1){
          $(".list #message").length && $(".list #message").addClass('red-d');
          if(!$(".notification .img-not .not-i").length){
            $(".notification .img-not").append("<i class='not-i'>" + res.new_message_count + "</i>");
          } else {
            $(".notification .img-not .not-i").text(res.new_message_count);
          }
        }else{
          $(".notification .img-not .not-i").length && $(".notification .img-not .not-i").remove();
          $(".list #message").length && $(".list #message").removeClass('red-d');

        }
        $(".notification .unreadCount").length && $(".notification .unreadCount").text(res.new_message_count);
      }

      if(type == "notice"){
        if (res.has_new_message >= 1 && !$(".notice-top div:first .not-i").length) {
          $(".notice-top div:first").append("<i class='not-i'></i>");
        } else if(res.has_new_message == 0) {
          $(".notice-top div:first").children().remove();
        }
      }

      if(type == "private"){
        if (res.has_new_message >= 1 && !$(".notice-top div:last .not-i").length) {
          $(".notice-top div:last").append("<i class='not-i'></i>");
        } else if(res.has_new_message == 0) {
          $(".notice-top div:last").children().remove();
        }
      }
    },
  });
}

function freshUserToken(fn_request, fn_request_params) {
  var _this = this;
  $.ajax({
    url: getServer("passport") + "/api2/accesstoken",
    data: { login_token: wfGetCookie("wikidbLoginToken") },
    dataType: "json",
    async: false,
  })
    .done(function (result) {
      token = result.access_token;
      if (!token) {
        if (typeof isAppClient == "function" && isAppClient()) {
          if (window.app && typeof window.app.openApp == "function") {
            window.app.openApp(JSON.stringify({ type: "login" }));
          }
        } else {
          window.location.href =
            getServer("passport") +
            "/login" +
            "?continue=" +
            encodeURIComponent(window.location.href);
        }
        return;
      }
      if (typeof wfSetCookie === "function") {
        wfSetCookie(
          "wikidbAccessToken",
          result.access_token,
          "60",
          ".mbalib.com"
        ); //更新token
      }
      fn_request(fn_request_params);
    })
    .fail(function () {});
}

// 消息列表接口
function getGroupListNew(type) {
  $("#newList").children().remove();
  $(".noticePop .loading").show();
  var qsData = {
    access_token: token,
    group_type: type,
  };
  $.ajax({
    url: getServer("www") + "/messageapi/getGroupList",
    data: qsData,
    type: "POST",
    dataType: "json",
    crossDomain: true,
    xhrFields: {
      withCredentials: true,
    },
    success: function (res) {
      if (res.errorno == "10001") {
        freshUserToken(getGroupListNew, type);
        return;
      }

      $(".noticePop .loading").hide();

      let result = res.data;
      if (result && result.length > 0) {
        smallPopObj.groupList = result;
        let arr = localStorage.getItem("messageDelete")
          ? localStorage.getItem("messageDelete").split(",")
          : "";

        if(arr.length > 0 && arr) {
          arr.forEach(function(items,indexs){
            result.forEach(function(item,index){

              if(items == item.group_id) {
                if(item.message_new_count > 0){
                  arr.splice(indexs,1);
                }
                result.splice(index,1);
              }
            })
          })
          localStorage.setItem('messageDelete',arr);
        }

        if (result.length == 0) {
          newsNo();
          return;
        }

        $("#newList").children().remove();
        smallPopObj.noticeCount = 0;

        result.forEach(function (item) {
          smallPopObj.noticeCount += item.message_new_count;

          let str = "<li data-id='" + item.group_id + "'>";
          if (item.message_new_count > 0 && item.message_new_count < 10) {
            str += "<i class='newCount w16'>" + item.message_new_count + "</i>";
          } else if (
            item.message_new_count > 10 &&
            item.message_new_count < 1000
          ) {
            str += "<i class='newCount'>" + item.message_new_count + "</i>";
          } else if (item.message_new_count >= 1000) {
            str += "<i class='newCount'>999</i>";
          }
          str += "<img src='" + item.group_logo + "'>";
          str +=
            "<div class='new-groupName'><p class='group_p'><span class='g_name " +
            (item.message_new_count > 0 ? "" : "grey") +
            "'>" +
            item.group_name +
            "</span><span class='m_createtime'>" +
            formateDate(item.message_createtime) +
            "</span></p><p class='m_content'>" +
            escapeHTML(item.message_content) +
            "</p></div>";
          str += "</li>";
          $("#newList").append(str);
        });

        if(smallPopObj.noticeCount > 0){
          if(type == "notice"){
            !$(".notice-top div:first .not-i").length && $(".notice-top div:first").append("<i class='not-i'></i>");
          }
    
          if(type == "private"){
            !$(".notice-top div:last .not-i").length && $(".notice-top div:last").append("<i class='not-i'></i>");
          }
        } else {
          type == "notice" && $(".notice-top div:first").children().remove();
          type == "private" && $(".notice-top div:last").children().remove();
        }
      } else {
        newsNo();
      }
    },
  });
}

function newsNo() {
  $("#newList").children('.newsNo').remove();
  let str = '<div class="newsNo">还没有消息哦~</div>';
  $("#newList").append(str);
}
